<?php
/**
 * Partenaires
 *
 * Description de la classe
 *
 * @author David
 */
class Partner extends Object {
    protected $id;
    protected $nom;
    protected $logo;
    protected $description;
    protected $video;
    protected $site;
    protected $email;
    protected $password;
    protected $bandeau;
    protected $couleur_id;
    protected $added;

    function __construct($id="", $params=array()) {
        if($id != "") {
            $this->id = $id;
            foreach($params as $key => $p) {
                $this->$key = $p;
            }
        }
    }

    public function load() {
        $db = Database::getInstance();
        $sql = "SELECT * FROM partenaires WHERE id = '".$this->id."'";
        $result = $db->query($sql);
        if(sizeof($result) > 0) {
            foreach($result[0] as $key => $p) {
                $this->$key = $p;
            }
            return;
        }
        if(DEBUG) echo("Objet inconnu");
        return false;
    }

    function __toString() {
        if(!isset($this->titre)) $this->load();
        return $this->titre;
    }

    public static function getAllPartners($limit_start="", $limit_end=""){
        $db = Database::getInstance();
        $sql = "SELECT * FROM partenaires";
        if(($limit_start==0 || $limit_start!="") && $limit_end!=""){
            $sql.=" LIMIT ".$limit_start.", ".$limit_end;
        }
        $result = $db->query($sql);
        $allPartners = array();
        foreach($result as $line){
            $allPartners[] = new Partner($line['id'], $line);
        }
        return $allPartners;
    }

    public function getSmallUrl(){
        if(strpos($this->site,'http://')===false){
            $new_site = $$this->site;
        }else{
            $new_site = substr($this->site,7);
        }
        return $new_site;
    }
}
?>
